package com.campusflea.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.campusflea.R;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * ListView适配器
 *
 */
public class MyAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<HashMap<String, Object>> list;
	public MyAdapter(Context context, ArrayList<HashMap<String, Object>> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		final ViewHolder holder;
		if (convertView == null) {
			convertView  = LayoutInflater.from(context).inflate(R.layout.user, null);
			holder = new ViewHolder();

			holder.imageView = (ImageView) convertView.findViewById(R.id.user_pic);
			holder.shop_name = (TextView) convertView.findViewById(R.id.user_js);
			holder.shop_disc = (TextView) convertView.findViewById(R.id.user_jg);
			holder.shop_price = (TextView) convertView.findViewById(R.id.user_dz);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.imageView.setImageBitmap((Bitmap)list.get(position).get("shop_pic"));
//		holder.imageView.setImageDrawable((Drawable) list.get(position).get("shop_pic"));
		holder.shop_name.setText(list.get(position).get("shop_name").toString());
		holder.shop_disc.setText("\u3000\u3000"+list.get(position).get("shop_disc").toString());
		holder.shop_price.setText("￥"+list.get(position).get("user_price").toString());
		//接口回调的方法，完成图片的读取;
//		DownImage downImage = new DownImage(list.get(position).get("picname_hospital_s").toString());
//		downImage.loadImage(new ImageCallBack() {
//
//			@Override
//			public void getDrawable(Drawable drawable) {
//				holder.picname_hospital_s.setImageDrawable(drawable);
//			}
//		});

		return convertView;
	}
	class ViewHolder{
		TextView shop_name,shop_disc,shop_price;
		ImageView imageView;
	}
}